/**
 * 
 */
package com.precisosoft.mathematize.client.view;

import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;
import com.precisosoft.mathematize.client.view.handlers.ErrorPageUiHandlers;
import com.precisosoft.mathematize.client.presenter.ErrorPagePresenter;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;

/**
 * @author jewettdx
 * 
 */
public class ErrorPageView extends ViewWithUiHandlers<ErrorPageUiHandlers>
		implements ErrorPagePresenter.MyView {

	private static String html = "<div>\n"
			+ "<table align=\"center\">\n"
			+ "  <tr>\n"
			+ "<td>&nbsp;</td>\n"
			+ "</tr>\n"
			+ "  <tr>\n"
			+ "<td>&nbsp;</td>\n"
			+ "</tr>\n"
			+ "  <tr>\n"
			+ "<td>&nbsp;</td>\n"
			+ "</tr>\n"
			+ "  <tr>\n"
			+ "    <td style=\"font-weight:bold;\">An error has occurred.</td>\n"
			+ "  </tr>\n" + "  <tr>\n" + "<td>&nbsp;</td>\n" + "</tr>\n"
			+ "  <tr>\n"
			+ "<td>Try this action again. If the problem continues,</td>\n"
			+ "</tr>\n" + "  <tr>\n"
			+ "<td>check the Mathematize forums for a solution or</td>\n"
			+ "</tr>\n" + "  <tr>\n"
			+ "<td>contact your Mathematize administrator.</td>\n" + "</tr>\n"
			+ "  <tr>\n" + "<td>&nbsp;</td>\n" + "</tr>\n" + "  <tr>\n"
			+ "    <td id=\"okButtonContainer\"></td>\n" + "  </tr>\n"
			+ "</table>\n" + "</div>\n";

	private HTMLPanel panel;

	private final Button okButton;

	public ErrorPageView() {

		panel = new HTMLPanel(html);

		okButton = new Button("OK");

		panel.add(okButton, "okButtonContainer");

		bindCustomUiHandlers();
	}

	protected void bindCustomUiHandlers() {

		okButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				if (getUiHandlers() != null) {
					getUiHandlers().onOkButtonClicked();
				}
			}
		});
	}

	@Override
	public Widget asWidget() {
		return panel;
	}

}
